/**
 * Created by yuris on 24.02.15.
 */
package InterfaceObjects.BottomPanel {
import starling.display.Image;
import starling.display.Sprite;
import starling.events.Touch;
import starling.events.TouchEvent;
import starling.events.TouchPhase;
import starling.filters.ColorMatrixFilter;

public class PaintItem extends  Sprite{
    private var _skinImage:Image;
    private var _contentImage:Image;
    private var _id:String;
    public static var TYPE_WALL:String = "TYPE_WALL";
    public static var TYPE_FLOOR:String = "TYPE_FLOOR";
    public function PaintItem(id:String, contentImageName:String, type:String) {
        this._id = id;

        this._skinImage = GraphicFactory.getImageByName("Interface/Skins/bottom_panel_item_skin");
        this._skinImage.alignPivot();
        this._skinImage.width = 90;
        this._skinImage.height = 91 + 15;
        this.addChild(this._skinImage);

        this._contentImage = GraphicFactory.getImageByName(contentImageName);
        this._contentImage.alignPivot();
        //this._contentImage.x = this._skinImage.x;
        //this._contentImage.y = this._skinImage.y;
        if(type == TYPE_FLOOR){
            this._contentImage.scaleX = this._contentImage.scaleY = 0.5;
            this._contentImage.rotation = Math.PI/4;
        } else if(type == TYPE_WALL){
            this._contentImage.skewY =  0.0;
            this._contentImage.scaleX = 0.5;
            this._contentImage.scaleY = 0.5;
        }

        this._contentImage.touchable = false;
        this.addChild(this._contentImage);

        this.addEventListener(TouchEvent.TOUCH, HANDLER_touch);
    }


    private var _bufTouch:Touch;
    private function HANDLER_touch(event:TouchEvent):void {
        this._bufTouch = event.getTouch(this);
        if(this._bufTouch){
            switch(this._bufTouch.phase){
                case TouchPhase.HOVER:
                    this._skinImage.filter = BottomPanel.itemHoverFilter;
                    break;
                case TouchPhase.BEGAN:
                    this._skinImage.filter = null;
                    break;
            }
        } else {
            this._skinImage.filter = null;
        }
    }

    public function showContentImage():void {
        if(this.parent && this._contentImage){
            this._contentImage.x = this.x;
            this._contentImage.y = this.y- 10;
            this.parent.addChild(this._contentImage);
        }
    }

    public function get id():String {
        return _id;
    }
}
}
